package com.mes.basicdata.service;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.util.StringHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bstek.dorado.annotation.DataProvider;
import com.mes.basicdata.dao.iface.IRoutingDao;
import com.mes.basicdata.domain.Dept;
import com.mes.basicdata.domain.Routing;
import com.mes.common.service.BasicService;
@Service
public class RoutingService extends BasicService<Routing>{
	@Autowired
	private IRoutingDao routingDao;
	
	@DataProvider
    public Collection<Routing> queryForCondition( Map<String, Object> params) throws Exception {
        if (null != params) {
            String routingId = (String)params.get("routingId");
            String routingName = (String) params.get("routingName");
            String routingType = (String)params.get("routingType");
            String masterShopUid = (String)params.get("masterShopUid");
             
          String whereCase = "";
            if (StringHelper.isNotEmpty(routingId)) {
                whereCase += " AND routingId like '%" + routingId + "%' ";
            }
             
            if (StringHelper.isNotEmpty(routingName)) {
                whereCase += " AND routingName like '%" + routingName + "%' ";
            }
             
            if (StringHelper.isNotEmpty(routingType)) {
                whereCase += " AND routingType like '%" + routingType + "%' ";
            }
             
            if (StringHelper.isNotEmpty(masterShopUid)) {
                whereCase += " AND masterShopUid like '%" + masterShopUid + "%' ";
            }
            String hql = " from Routing where 1=1 " + whereCase;
            return routingDao.find( hql);
        } else
        	return routingDao.loadAll();
        	//return routingDao.find("from Routing where routingId = '1988226'");
    }
	
	@DataProvider
	public List<Routing> getRoutingByPartNumber(Map<String, Object> params){
		try {
			return routingDao.getRoutingByPartNumber(params);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	@DataProvider
	public List<Routing> getRoutingByPartUid(Map<String, Object> params){
		List<Routing> list = new ArrayList<Routing>();
		
		try {
			list = routingDao.findByProperty("partUid", params);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
}
